package com.google.dagger2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.dagger2.mvp.bean.User;
import com.google.dagger2.mvp.view.IUserLoginView;
import com.google.dagger2.mvp.view.UserLoginPresenter;

public class UserLoginActivity extends AppCompatActivity implements IUserLoginView {

    private EditText et_password;
    private EditText et_username;
    private Button btn_login;
    private Button btn_clear;
    private ProgressBar pb_progress;
    private UserLoginPresenter mUserLoginPresenter = new UserLoginPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViews();
    }

    private void initViews() {
        et_username = (EditText) findViewById(R.id.et_username);
        et_password = (EditText) findViewById(R.id.et_password);

        btn_login = (Button) findViewById(R.id.btn_username);
        btn_clear = (Button) findViewById(R.id.btn_password);

        pb_progress = (ProgressBar) findViewById(R.id.pb_progress);

        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mUserLoginPresenter.login();
            }
        });
        btn_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mUserLoginPresenter.clear();

            }
        });
    }

    @Override
    public String getUserName() {
        return et_username.getText().toString();
    }

    @Override
    public String getPassword() {
        return et_password.getText().toString();
    }

    @Override
    public void clearUserName() {
        et_username.setText("");
    }

    @Override
    public void clearPassWord() {
        et_password.setText("");
    }

    @Override
    public void ShowLoading() {
        pb_progress.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideLoading() {
        pb_progress.setVisibility(View.GONE);
    }

    @Override
    public void toMainActivity(User user) {
        Toast.makeText(this,"login Success,to MainActivity",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showFailError() {
        Toast.makeText(this,"login Failed",Toast.LENGTH_SHORT).show();
    }
}
